package org.lc.service.system.entity;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.lc.platform.mybatis.entity.BaseEntity;
import org.lc.platform.mybatis.handler.SM4Handler;
import org.lc.platform.mybatis.manager.annotation.ManyToMany;
import org.lc.platform.swagger.interfaces.Add;

/**
 * user
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName(autoResultMap = true)
@ToString(callSuper = true)
public class SysUser extends BaseEntity implements Serializable {
    /**
     * 账号
     */
    @NotEmpty(message = "账号不能为空", groups = {Add.class})
    @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED)
    private String account = "77";

    /**
     * 用户名
     */
    @NotEmpty(message = "用户姓名不能为空", groups = {Add.class})
    @Schema(description = "用户姓名", requiredMode = Schema.RequiredMode.REQUIRED)
    public String name;

    /**
     * 手机号
     */

    @TableField(typeHandler = SM4Handler.class)
    @NotEmpty(message = "用户手机号不能为空", groups = {Add.class})
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不对")
    @Schema(description = "用户手机号", requiredMode = Schema.RequiredMode.REQUIRED)
    private String phone;

    /**
     * 手机验证码
     */

    @TableField(exist = false)
    @Schema(description = "手机号验证码", hidden = true)
    private String code;

    /**
     * 账号状态(0:正常;1:冻结;2:异常)
     */
    @Schema(description = "账号状态(0:正常;1:冻结;2:异常)", defaultValue = "0", type = "int")
    private Integer status;

    /**
     * 是否禁用
     */
    @Schema(description = "是否禁用", defaultValue = "false", type = "boolean")
    private Boolean forbidden;

    /**
     * 密码
     */
    @Schema(description = "密码", hidden = true)
    private String password;

    /**
     * '密码加盐标识'
     */
    @Schema(description = "'密码加盐标识'", hidden = true)
    private String salt;
    /**
     * '密码加盐标识'
     */
    @Schema(description = "'是否在线'", hidden = true)
    private boolean online;
    /**
     * 删除时间
     */
    @TableField(select = false)
    @JsonIgnore
    @Schema(description = "删除标识", hidden = true)
    @TableLogic
    private LocalDateTime deleteTime;

    @ManyToMany(middleTable = SysRoleUser.class, middleSelfField = "SysUserId", middleTargetField = "SysRoleId")
    @TableField(exist = false)
    private List<SysRole> roles;

    @ManyToMany(middleTable = SysDepartmentUser.class, middleSelfField = "SysUserId", middleTargetField = "SysDepartmentId")
    @TableField(exist = false)
    private List<SysDepartment> department;

    @Serial
    private static final long serialVersionUID = 1L;
}